/*
The analyses are organized for the specific results discussed
in the section titled: 

Why does sample size matter?
*/

use "../Metadata/tess_analysisdata.dta", clear

*number of tests with Cohen's d measure -- 941
	count if d<. & insample==1

*correlation between sample size and effect size -- -.03
	pwcorr d N_person if insample == 1, sig


*median effect size for experiments comparing exp conditions -- .08
	table hyp_type if insample == 1, stat(median d)


*statistical power, given N=1500, and given effect size
	
	* effect size .2 -- power = 97%
	power twomeans 0, diff(.2) n(1500)

	* effect size .08 -- power = 34%
	power twomeans 0, diff(.08) n(1500)

	
* count number of p-values < .001 -- 185
	count if twop < .001 & insample == 1

* count number of p-values > .01  and < .05 -- 60
	count if twop > .01 & twop < .05 & insample == 1

	
* power needed to detect non-significant hypotheses
	
	*median d for non-sig tests comparing treatment conditions -- .05769
	table hyp_true if insample==1 & hyp_type==1, stat(median d)

	*sample size needed to detect median d -- 9436
	power twomeans 0, diff(0.05769) power(0.8)

	*typical TESS study size -- mean =1994; median = 2015
	sum samplesize if hyp_num==1, d






